package com.sskj.mine.presenter;

import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;
import com.sskj.common.base.HttpData;
import com.sskj.common.util.SPUtil;
import com.sskj.common.util.ToastUtil;
import com.sskj.lib.SPConfig;
import com.sskj.lib.http.JsonCallBack;
import com.sskj.mine.bean.GoogleCode;
import com.sskj.mine.http.HttpConfig;
import com.sskj.mine.ui.activity.VerifyGoogleActivity;


public class VerifyGoogleActivityPresenter extends BasePresenter<VerifyGoogleActivity> {
    public void submit(String chromeCode, String authCode, String secret, String qrcode) {
        OkGo.<HttpData<Object>>post(HttpConfig.BASE_URL + HttpConfig.BINDCHROME)
                .params("code", chromeCode)
                .params("stockUserId", SPUtil.get(SPConfig.ID, ""))
                .params("telCode", authCode)
                .params("secret", secret)
                .params("qrcode", qrcode)
                .execute(new JsonCallBack<HttpData<Object>>(this) {
                    @Override
                    public void onSuccess(Response<HttpData<Object>> response) {
                        toggleGoogleVerify(chromeCode);
                    }
                });
    }


    public void requestData() {
        OkGo.<HttpData<GoogleCode>>post(HttpConfig.BASE_URL + "/app/googleAuth/genSecret")
                .execute(new JsonCallBack<HttpData<GoogleCode>>(this) {
                    @Override
                    public void onSuccess(Response<HttpData<GoogleCode>> response) {
                        mView.onGoogleCodeSuccess(response.body().getData());
                    }

                });
    }



    // 开启谷歌认证
    public void toggleGoogleVerify(String code) {
        OkGo.<HttpData<Object>>post(HttpConfig.BASE_URL + HttpConfig.SET_GOOGLE_VERIFY)
                .params("code", code)
                .params("stockUserId", SPUtil.get(SPConfig.ID, ""))
                .execute(new JsonCallBack<HttpData<Object>>() {
                    @Override
                    public void onSuccess(Response<HttpData<Object>> response) {
                        mView.onBindSuccess();
                    }
                });
    }
}
